package com.yuntuzhilian.chapter3;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * @author MrWang-shuizhishuiheshui
 * @description 字节流的形式处理读入信息
 */
public class TestFileInputStream {
    public static void main(String[] args) {
        FileInputStream fis=null;

        try {
            //创建输入流对象fis , 异常:FileNotFoundException,文件无法找到异常
            fis=new FileInputStream("test.txt");
            //创建字节数组,保存读取的内容
            byte[] words=new byte[1024];

            //fis.read(words) : 读去文件内容,并存在缓冲区数组中
            while((fis.read(words))!=-1){
                System.out.println(new String(words));
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //释放资源
            if (fis!=null){
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }


    }
}
